<html>
<head>
<TITLE>CSE5317/4305 Project #6</TITLE>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<center>
<H1>CSE5317/4305 Project #6 (Rest of IRs)</H1>
Due Wednesday April 16 at 11:59pm<p>
Worth 16% of your project grade
</center>
<p>
<hr>
<p>
For this project, you are asked to generate the
Intermediate Representation (IR) structures
for every AST left out from project #5.
<p>
You need to modify the file <tt>Code.gen</tt>
to handle
array and record construction, array indexing, record projection,
function/procedure call, and
function/procedure prologue/epilogue.
The frame layout will be similar to that in <a href="http://lambda.uta.edu/cse5317/notes/node34.html">Section 7.2</a> in the notes,
but function arguments are pushed in the stack from left to right.
The register <tt>v0</tt> is used in passing the static link from the caller to the callee.
This is done implicitly inside the IR <tt>Call(f,sl,...)</tt>.
There are two different cases for the static link.
Lets say that caller_level and callee_level are the nesting
levels of the caller and the callee procedures (recall that the nesting
level of a top-level procedure is 0, while the nesting level of
a nested procedure embedded inside another procedure with nesting level n, is n+1).
When the callee is lexically inside the caller's body, that is, when callee_level=caller_level+1, the static link is
<tt>Reg(fp)</tt>.
Otherwise, we follow the static link of the caller d+1 times, where d=caller_level-callee_level (the difference
between the nesting level of the caller from that of the callee). For d=0, that is, when both caller
and callee are at the same level, we have
<tt>Mem(Binop(PLUS,Reg(fp),Const(-8)))</tt>.
For d=2 we have:
<pre>
Mem(Binop(PLUS,Mem(Binop(PLUS,Mem(Binop(PLUS,Reg(fp),Const(-8))),Const(-8))),Const(-8)))
</pre>
<p>
You need to run your parser against all <tt>tests/*.pcat</tt> files.
For example:
<pre>
run 6 hello
</pre>
You also need to compare your output with that of the solution:
<pre>
solution 6 hello
</pre>
Another test, which is optional, is to temporarily remove the <tt>Mips.gen</tt> file and run, eg.
<pre>
run 7 hello
</pre>
that will convert your IR code into MIPS using the solution and will run it using SPIM.
<p>
After ensuring that your program compiles and executes correctly,
cleanup your <tt>pcat</tt> directory using
<tt>
clean
</tt>
Then, if you are using Linux, archive your file using <tt>tar cvf pcat.tar pcat</tt>.
If you are using Windows, zip the whole directory into the file <tt>pcat.zip</tt>.
Then submit your file (<tt>pcat.tar</tt> or <tt>pcat.zip</tt>) here:
<p>
<form enctype="multipart/form-data" action="/cgi-bin/php/handin.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <input type="hidden" name="class" value="cse5317" />
    <input type="hidden" name="assignment" value="proj6" />
Submit this file: <input name="userfile" type="file" size="50"/><br/>
    <input type="submit" value="Send File" />
</form>
<p>

<hr>
<P>
<ADDRESS>Last modified: 01/09/08 by <A HREF="http://lambda.uta.edu/">Leonidas Fegaras</A></ADDRESS>
